package com.ls.pattern.establish.factory.abstractfactory;

import com.ls.pattern.establish.factory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OrderPizza {

    AbsFactory absFactory;

    public OrderPizza(AbsFactory absFactory) {
        String orderType = "";

        do {
            orderType = getType();
            Pizza pizza = absFactory.createPizza(orderType);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }

        } while (true);
    }


    public void setAbsFactory(AbsFactory absFactory) {
        this.absFactory = absFactory;
    }

    private String getType() {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

}
